﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using App.Utilities.Web.Handlers;
using CRMBiz;
using Newtonsoft.Json;

namespace CRMWeb.WebServices
{
    /// <summary>
    /// Summary description for AssessmentLasResult
    /// </summary>
    public class AssessmentLasResult : BaseHandler
    {

        public override void OnMethodInvoke(OnMethodInvokeArgs e)
        {
            context.Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache);
            context.Response.Cache.SetExpires(DateTime.MinValue);
            context.Response.Cache.SetNoStore();

            //e.Cancel = true;

            SetResponseContentType(ResponseContentTypes.HTML);
        }

        public override void AfterMethodInvoke(object result)
        {
            base.AfterMethodInvoke(result);
        }

        //user defined function
        #region private method


        //Select all data
        public void AssessmentLastResultSelect()
        {
            string strJson = null;
            try
            {
                var pageIndex = string.IsNullOrEmpty(context.Request["page"]) ? 1 : int.Parse(context.Request["page"]);
                var pageSize = string.IsNullOrEmpty(context.Request["rows"]) ? 10 : int.Parse(context.Request["rows"]);

                DataSet ds = AssessmentLastResultHandler.GetAssessmentLastResultList(pageIndex, pageSize);
                var total = (ds.Tables[0].Rows.Count > 0) ? Convert.ToInt32(ds.Tables[0].Rows[0]["Total"]) : 0;
                strJson = JsonConvert.SerializeObject(ds.Tables[0]);
                strJson = "{\"total\":\"" + total.ToString() + "\",\"rows\":" + strJson + "}";

                context.Response.Write(strJson);
            }
            catch (Exception)
            {
                throw;
            }
        }

        //Add new assessment data
        public int AssessmentLastResultAdd(string AssessmentLastResult)
        {
            int intReturnValue = 0;
            try
            {
                intReturnValue = AssessmentLastResultHandler.AddAssessmentLastResult(AssessmentLastResult);
            }
            catch (Exception)
            {
                throw;
            }
            return intReturnValue;
        }

        //Edit assessment data
        public int AssessmentLastResultEdit(int AssessmentLId, string AssessmentLastResult)
        {
            int intReturnValue = 0;
            try
            {
                intReturnValue = AssessmentLastResultHandler.EditAssessmentLastResult(AssessmentLId, AssessmentLastResult);
            }
            catch (Exception)
            {
                throw;
            }
            return intReturnValue;
        }


        //Delete assessment data
        public bool AssessmentLastResultDelete(int AssessmentLId)
        {
            bool flag = false;
            try
            {
                flag = AssessmentLastResultHandler.DeleteAssessmentLastResult(AssessmentLId);
            }
            catch (Exception)
            {
                throw;
            }
            return flag;
        }


        #endregion
    }
}